<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
	<style type="text/css">
		table{
			text-align: center;
		}
		table thead{
			font-weight: bold;
		}
	</style>
</head>
<body>
	<div class="btn-group">
	  <button type="button" class="btn btn-primary dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
	    评价类型 <span class="caret"></span>
	  </button>
	  <ul class="dropdown-menu">
	   	<li><a href="#" onclick="showRight('<%=request.getContextPath() %>/commentlist','')">全部</a></li>
	    <li><a href="#" onclick="showRight('<%=request.getContextPath() %>/commentlist','1')">好评</a></li>
	    <li><a href="#" onclick="showRight('<%=request.getContextPath() %>/commentlist','2')">一般</a></li>
	    <li><a href="#" onclick="showRight('<%=request.getContextPath() %>/commentlist','3')">差评</a></li>
	  </ul>
	</div>
	<br><br>
	<div class="table-responsive">
	<table class="table table-striped table-hover table-bordered ">
		<thead>
			<tr class="info">
				<td>产品编号</td>
				<td>用户名</td>
				<td>评价类型</td>
				<td>最后一次更新</td>
				<td>操作</td>
			</tr>
		</thead>
		<tbody>
			<c:forEach items="${list }" var="comment">
			<tr>
				<td>${comment.productId }</td>
				<td>${comment.username}</td>
				<c:if test="${comment.type eq 1}"><td>好评</td></c:if>
				<c:if test="${comment.type eq 2}"><td>一般</td></c:if>
				<c:if test="${comment.type eq 3}"><td>差评</td></c:if>
				<td>${comment.updateTime }</td>
				<td><button class="btn btn-primary" onclick="showRight('<%=request.getContextPath() %>/commentdetail','${comment.id}')">查看</button>&nbsp;&nbsp;<button class="btn btn-danger" onclick="deletecomment('${comment.id}')">删除</button></td>
			</tr>
			</c:forEach>
		</tbody>
	</table>
	</div>
	<span class="col-md-7 col-sm-4"></span>
		 <ul class="pager col-md-5 col-sm-8">
			 <li>共${page.pages }页，当前第${page.pageNum }页</li>
			 <li><a href="JavaScript:void()" onclick="showRight('<%=request.getContextPath() %>/commentlist','','${page.firstPage}')">首页</a></li>
			 <li><a href="JavaScript:void()" onclick="showRight('<%=request.getContextPath() %>/commentlist','','${page.prePage}')">上一页</a></li>
			 <li><a href="JavaScript:void()" onclick="showRight('<%=request.getContextPath() %>/commentlist','','${page.nextPage}')">下一页</a></li>
			 <li><a href="JavaScript:void()" onclick="showRight('<%=request.getContextPath() %>/commentlist','','${page.lastPage}')">尾页</a></li>
		 </ul>
	 <script type="text/javascript">
	 	function deletecomment(id) {
			if(window.confirm('确定要删除该评论吗？')){
				if(id!=''){
					$.ajax({
						url:'<%=request.getContextPath() %>/delete/comment',
						data:{
							id:id
						},
						success:function(data){
							if(data=="succ"){ 
								alert('删除成功！')
								showRight('<%=request.getContextPath() %>/commentlist')
							}
							else if(data=='nologin'){
				                location.href='<%=request.getContextPath() %>/adminlogin'
				             }
							else{ alert('操作失败') }
						},
						erro:function(){ alert('请求出错') }
					})
				}else{ alert('未选中评论') }
			}
		}
	 </script>
</body>
</html>